package com.kaiwukj.android.ufamily;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.kaiwukj.android.mcas.di.component.AppComponent;
import com.kaiwukj.android.ufamily.app.MyApplication;
import com.kaiwukj.android.ufamily.mvp.http.callback.ApiCallBack;
import com.kaiwukj.android.ufamily.mvp.http.entity.base.ListResp;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.KeeperOrderResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.KeeperResult;
import com.kaiwukj.android.ufamily.mvp.model.KeeperModel;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RunWith(AndroidJUnit4.class)
public class KeeperTest {

    // @Inject
    KeeperModel mModel;
    //RxErrorHandler mErrorHandler;

    @Before
    public void init() {

        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();


        AppComponent appComponent = MyApplication.getInstance().getAppComponent();
        mModel = new KeeperModel(appComponent.repositoryManager());

        /*mErrorHandler = RxErrorHandler.builder()
                .with(appContext)
                .responseErrorListener(new ResponseErrorListenerImpl())
                .build();*/
    }

    @Test
    public void testFetchList() {
        mModel.fetchCommunityKeeperList()
                .subscribe(new ApiCallBack<List<KeeperResult>>() {
                    @Override
                    public void onSuccess(@NonNull List<KeeperResult> result) {
                        System.out.println("results------------------------->" + GsonUtils.toJson(result));
                    }
                });
    }

    @Test
    public void testFetchSysList() {
        mModel.fetchSysKeeperList()
                .subscribe(new ApiCallBack<List<KeeperResult>>() {
                    @Override
                    public void onSuccess(@NonNull List<KeeperResult> result) {
                        LogUtils.d("results------------------------->" + GsonUtils.toJson(result));
                    }
                });
    }

    @Test
    public void testBind() {
        Map<String, Object> params = new HashMap<>();
        params.put("housekeeperId", 1);
        mModel.bindKeeper(params)
                .subscribe(new ApiCallBack<Integer>() {
                    @Override
                    public void onSuccess(@NonNull Integer result) {
                        LogUtils.d("result-------------------->" + result);
                    }
                });
    }

    @Test
    public void testGetMyKeeper() {
        mModel.getMyKeeperInfo()
                .subscribe(new ApiCallBack<KeeperResult>() {
                    @Override
                    public void onSuccess(@NonNull KeeperResult result) {
                        LogUtils.d("result------------------------->" + GsonUtils.toJson(result));
                    }

                    @Override
                    public void onFailure(@NonNull Throwable e) {
                        super.onFailure(e);
                        e.printStackTrace();
                    }
                });
    }

    @Test
    public void testAddOrder() {
        mModel.addKeeperOrder(1, 6, "2020-08-01 11:00:00", "23#514")
                .subscribe(new ApiCallBack<Integer>() {
                    @Override
                    public void onSuccess(@NonNull Integer result) {
                        LogUtils.d("result------------------------->" + result);
                    }
                });
    }

    @Test
    public void testFetchOrder() {
        mModel.fetchKeeperOrder(1, 12)
                .subscribe(new ApiCallBack<ListResp<KeeperOrderResult>>() {
                    @Override
                    public void onSuccess(@NonNull ListResp<KeeperOrderResult> result) {
                        LogUtils.d("result------------------------->" + GsonUtils.toJson(result.getList()));
                    }
                });
    }

    @Test
    public void testAddReport() {
        mModel.addComplain("服务态度太差", 1)
                .subscribe(new ApiCallBack<Integer>() {
                    @Override
                    public void onSuccess(@NonNull Integer result) {
                        LogUtils.d("result------------------------->" + result);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        LogUtils.e("result------------------------->" + e.getMessage());
                    }
                });
    }

}
